<template>
    <div>
      <table>
        <tr>
          <td>
            商品名称
          </td>
          <td>
            商品图片
          </td>
          <td>
            商品价格
          </td>
          <td>
            操作
          </td>

        </tr>
        <tr v-for="item in goods">
          <td>
            {{ item.name }}

          </td>
          <td>
<!--            {{ item.img }}-->
            <img :src="'http://127.0.0.1:8000'+item.img" width="50" height="50">

          </td>
          <td>
            {{ item.price }}

          </td>
          <td v-if="detail==null">
            <button @click="on_detail(item.id)">评论</button>

          </td>
          <td v-else>
            已评价
            <br>
            <router-link :to="{path:'showdetail',query:{id:item.id}}">查看评论</router-link>

          </td>

        </tr>

      </table>
    </div>
</template>

<script>
  import axios from 'axios'
    export default {
        name: "show",
        data(){
          return{
            goods:[],
            detail:''
          }
        },
        mounted() {
          var detail = localStorage.getItem('detail');

          axios({
            url:'http://127.0.0.1:8000/show/',
            method:'GET'

          }).then(res=>{
            console.log(res);
            this.detail = detail;

            this.goods = res.data.goods
          })
        },
        methods:{
          on_detail(id){
            var name = localStorage.getItem('name');
            axios({
              url:'http://127.0.0.1:8000/datail/',
              method: 'POST',

            }).then(res=>{
              // console.log(name)
              if(name==null){
              this.$router.push('/login')
            }else {
              console.log(res);
              localStorage.setItem('id',id)
              this.$router.push('/datails')
              }

            })
          }
        }




    }
</script>

<style scoped>

</style>
